# CRAP5 - 5-bit Compact Representation of Alphabetical Patterns

CRAP5 is a 5 bit [character encoding](https://en.wikipedia.org/wiki/Character_encoding).
The premise of CRAP5 is that the English alphabet, plus a couple more formatting characters, can be neatly put into just 5 bits, instead of 8.

This means that for every byte, CRAP5 will nibble\* off three bits!
As such, CRAP5 has an efficiency of 137.5%!

## Character Set

The character set for CRAP5 is as follows:

| Character    | Dec | Hex  | Binary     |
|--------------|:---:|:---: |-----------:|
| Space        |  0  | 0x0  |    0b00000 |
| A            |  1  | 0x1  |    0b00001 |
| B            |  2  | 0x2  |    0b00010 |
| C            |  3  | 0x3  |    0b00011 |
| D            |  4  | 0x4  |    0b00100 |
| E            |  5  | 0x5  |    0b00101 |
| F            |  6  | 0x6  |    0b00110 |
| G            |  7  | 0x7  |    0b00111 |
| H            |  8  | 0x8  |    0b01000 |
| I            |  9  | 0x9  |    0b01001 |
| J            | 10  | 0xA  |    0b01010 |
| K            | 11  | 0xB  |    0b01011 |
| L            | 12  | 0xC  |    0b01100 |
| M            | 13  | 0xD  |    0b01101 |
| N            | 14  | 0xE  |    0b01110 |
| O            | 15  | 0xF  |    0b01111 |
| P            | 16  | 0x10 |    0b10000 |
| Q            | 17  | 0x11 |    0b10001 |
| R            | 18  | 0x12 |    0b10010 |
| S            | 19  | 0x13 |    0b10011 |
| T            | 20  | 0x14 |    0b10100 |
| U            | 21  | 0x15 |    0b10101 |
| V            | 22  | 0x16 |    0b10110 |
| W            | 23  | 0x17 |    0b10111 |
| X            | 24  | 0x18 |    0b11000 |
| Y            | 25  | 0x19 |    0b11001 |
| Z            | 26  | 0x1A |    0b11010 |
| .            | 27  | 0x1B |    0b11011 |
| ,            | 28  | 0x1C |    0b11100 |
| !            | 29  | 0x1D |    0b11101 |
| ?            | 30  | 0x1E |    0b11110 |
| Newline      | 31  | 0x1F |    0b11111 |


## Usage

```
usage: CRAP5 encoder/decoder [-h] [-d] [-i INFILE] [-o OUTFILE] [-u] [-x] [-b]

options:
  -h, --help            show this help message and exit
  -d, --decode          Decode data
  -i INFILE, --infile INFILE
  -o OUTFILE, --outfile OUTFILE
  -u, --uppercase       Print decoded data as uppercase
  -x, --hex             Print encoded data as hex
  -b, --bin             Print encoded data as binary
```

### Example Usage

Encode from STDIN (printed as hex, will be output as bytes by default)

```
$ echo 'Hello, world!' | crap5 -x
4158c7f0177c984efc
```

Encode from file

```
$ crap5 -i hello_world.txt
4158c7f0177c984efc
```

Decode from STDIN

```
$ echo 'Hello, world!' | crap5 | crap5 -d
hello, world!
```

Decode from file

```
$ echo 'Hello, world!' | crap5 > crap5.txt
$ crap5 -d -i crap5.txt
hello, world!
```

### Usage as a dependency

Because crap5 was designed to operate on STDIN and bytes from files, you will need to either do the same or simulate a byte readable object - for example with BytesIO. Both the encode and decode function are generators, yielding bytes as they encode/decode.

Encode:

```
>>> import io
>>> import crap5
>>> encoded = b''.join([x for x in crap5.encode(io.BytesIO(b'hello world'))])
b'AX\xc7\x82\xef\x93\x08'
```

Decode:

```
>>> import io
>>> import crap5
>>> b''.join([x for x in crap5.decode(io.BytesIO(b'AX\xc7\x82\xef\x93\x08'))]).lower()
b'hello world'
```

# FAQ - Frequently Asked Questions

- Q: When should I use this?
  - A: Never. Please don't use CRAP5.

# Appendix

- \* Pun intended.

